set hive.exec.dynamic.partition = true;
set hive.exec.dynamic.partition.mode = 'nonstrict';
set hive.exec.max.dynamic.partitions.pernode = 200;
set hive.exec.max.dynamic.partitions = 200;
insert overwrite table jms_dm.dm_waybill_collect_intime_plan
select
     taking_date
    ,waybill
    ,is_interrupted
    ,truncated_time
    ,receive_city_id
    ,receive_city
    ,region_code
    ,region_name
    ,receive_proxy_code
    ,receive_proxy
    ,receive_franchisee_code
    ,receive_franchisee
    ,receive_network_code
    ,receive_network_name
    ,actual_collect_code
    ,actual_collect_name
    ,plan_collect_code
    ,plan_collect_name
    ,actual_center_code
    ,actual_center_name
    ,collect_proxy_code
    ,collect_proxy
    ,is_diff_proxy
    ,actual_collect_time
    ,actual_send_time
    ,actual_collect_arr_time
    ,plan_collect_arr_time
    ,actual_center_arr_time
    ,hand_over_latest
    ,is_arr_collect_intime
    ,is_arr_center_intime
    ,hand_over_intime
    ,collect_responsible_code
    ,collect_responsible
    ,hand_over_responsible_code
    ,hand_over_responsible
    ,type
    ,order_source
    ,goods_type_code
    ,goods_type_name
    ,end_code
    ,end_name
    ,plan_arr_date
    ,plan_center_arr_time
    ,is_over
    ,shipment_no                   as shipment_no                    --实际首中心到件任务号（20220903新增）
    ,customer_code                 as customer_code                  --客户编号（20220903新增）
    ,total_days_t                  as total_days_t                   --T+x时效（20220903新增）
    ,center_planned_departure      as center_planned_departure       --中心规划发车时间-1小时（20220903新增）
    ,is_intime                     as is_intime                      --时效是否准点（20220903新增）
    ,express_type_code             as express_type_code              --产品类型编码(20221103新增)
    ,express_type_name             as express_type_name              --产品类型名称(20221103新增)
    ,last_area_code                as last_area_code                 --目的区/县编码            (20221113新增)
    ,last_area_name                as last_area_name                 --目的区/县名称            (20221113新增)
    ,last_city_code                as last_city_code                 --目的城市编码             (20221113新增)
    ,last_city_name                as last_city_name                 --目的城市名称             (20221113新增)
    ,last_agent_code               as last_agent_code                --目的代理区编码           (20221113新增)
    ,last_agent_name               as last_agent_name                --目的代理区名称           (20221113新增)
    ,first_nodal_send_time         as first_nodal_send_time          --始发集散发件扫描时间     (20221113新增)
    ,first_nodal_arrival_time      as first_nodal_arrival_time       --始发集散到件扫描时间     (20221113新增)
    ,first_center_send_time        as first_center_send_time         --始发转运中心发件扫描时间 (20221113新增)
    ,first_center_arrival_time     as first_center_arrival_time      --始发转运中心到件扫描时间 (20221113新增)
    ,if_yiqin_late                 as if_yiqin_late                  --是否疫情件               (20221213新增)
    ,if_route_late                 as if_route_late                  --路由晚点                 (20221213新增)
    ,if_center_send_timely         as if_center_send_timely          --是否交件晚点及时发出1:是,0:否(20221213新增)
    ,customer_name                    --客户名称
    ,first_nodal_agent_code           --实际交件集散点代理区编码
    ,first_nodal_agent_name           --实际交件集散点代理区名称
    ,first_nodal_fran_code            --实际交件集散点加盟商编码
    ,first_nodal_fran_name            --实际交件集散点加盟商名称
    ,shipment_shifts                  --实际交件中心任务班次
    ,taking_user_code                 --揽收业务员
    ,taking_user_name                 --揽收业务员
    ,actual_network_shipment_no       --网点发件任务单
    ,actual_nodal_shipment_no         --集散到件发件任务单
    ,first_network_plan_send_time     --始发网点规划发车时间
    ,first_nodal_plan_send_time       --始发集散规划发车时间
    ,hand_over_duty_flag              --不准点责任标识
    ,area_code                        --收件底层片区CODE
    ,area_name                        --收件底层片区名称
    ,first_nodal_bagging_time         --始发集散建包扫描时间
    ,order_mark_en                    -- 订单标签英文
    ,order_mark_zh                    -- 订单标签中文
    ,white_list_type                  -- 白名单类型0无1直发2车件分离
    ,plan_arr_date as dt
from jms_dm.dm_waybill_collect_intime
where dt >= date_sub('{{ execution_date | cst_ds }}',2)
and plan_arr_date = '{{ execution_date | cst_ds }}'
and hand_over_intime is not null
distribute by dt, pmod(hash(rand()),100)
;
